package com.render.gui;
import java.awt.Color;
import java.awt.Graphics2D;

import base.render.CosineWiggle;
import base.render.gui.Gui;


public class GuiTitle extends Gui
{
	private String title = "";
	private int titleLength = 0;
	private Color titleColor;
	private boolean shouldUpdateInit = true;
	
	private int tickCounter;
	
	private CosineWiggle theWiggle;
	private int origY;
	
	public GuiTitle(int par1, int par2, String par3)
	{
		super(par1, par2, 0);
		this.title = par3;
		this.titleLength = this.title.length() * 6;
		this.titleColor = this.getRandomColor();
		
		this.theWiggle = new CosineWiggle(this.rand).setModifiedWiggle(0.04F, 6F);
		this.theWiggle.resetTheWiggle();
	}
	
	public void onUpdate()
	{
		super.onUpdate();
		if (this.shouldUpdateInit)
		{
			if (this.x < (getWindowWidth() / 2) - (this.titleLength / 2) + 4)
			{
				this.x += 2;
			}
			else
			{
				this.origY = this.y;
				this.tickCounter = 100;
				this.shouldUpdateInit = false;
			}
			return;
		}
		
		if (tickCounter-- <= 0)
		{
			y = (int) (this.origY - this.theWiggle.doTheWiggle());
		}
	}
	
	public void onRender(Graphics2D par1Graphics)
	{
		super.onRender(par1Graphics);
		int fontSize = par1Graphics.getFont().getSize();
		par1Graphics.setColor(Color.GRAY);
		par1Graphics.fillRect(this.x-(int)(this.titleLength * 0.3), this.y-16, (int) (this.titleLength * 1.5), 48);
		par1Graphics.setColor(this.titleColor);
		par1Graphics.fillRect(this.x-4, this.y-8, this.titleLength, 32);
		par1Graphics.setColor(Color.WHITE);
		par1Graphics.drawString(title, x, y+fontSize);
	}
	
	public void setRandomTitleColor()
	{
		this.titleColor = this.getRandomColor();
	}
	
	private Color getRandomColor()
	{
		Color color = Gui.getRandomColor(this.rand);
		while(color == Color.GRAY || color == Color.WHITE)
		{
			color = Gui.getRandomColor(this.rand);
		}
		return color;
	}
	
	public boolean isDead()
	{
		return false;
	}
}
